home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
uwpc201.zip
/
UW-SRC.ZIP
/
MAIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-03
|
11KB
|
360 lines
//-------------------------------------------------------------------------
//
// MAIN.CPP - Main module for UW/PC Version 2.
//
// This file is part of UW/PC - a multi-window comms package for the PC.
// Copyright (C) 1990-1991 Rhys Weatherley
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 1, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// Revision History:
// ================
//
// Version DD/MM/YY By Description
// ------- -------- -- --------------------------------------
// 1.0 23/03/91 RW Original Version of MAIN.CPP
// 1.1 05/05/91 RW Clean up and begin to add file transfers.
// 1.2 08/06/91 RW Add cut/paste and mouse support to UW/PC.
// 1.3 27/09/91 RW Add ALT-W for "next window" key.
//
// You may contact the author by:
// =============================
//
// e-mail: rhys@cs.uq.oz.au
// mail: Rhys Weatherley
// 5 Horizon Drive
// Jamboree Heights
// Queensland 4074
// Australia
//
//-------------------------------------------------------------------------
#include <stdio.h> // Standard I/O routines.
#include "screen.h" // Screen accessing routines.
#include "client.h" // Client control routines.
#include "uw.h" // UW protocol routines.
#include "keys.h" // Keyboard handling routines.
#include "config.h" // Configuration routines.
#include "timer.h" // System timer routines.
#include "dialog.h" // Dialog box routines.
#include "files.h" // File transfer routines.
#include "comms.h" // Communications routines.
#include "clipbd.h" // Clipboard handling routines.
#include "mouse.h" // Mouse handling routines.
#include <dos.h> // "delay" is defined here.
#include <string.h> // String handling routines.
#pragma warn -par
//
// Define some useful macros for screen access.
//
#define SCRN_WIDTH (HardwareScreen.width)
#define SCRN_HEIGHT (HardwareScreen.height)
#define ATTR(x) (HardwareScreen.attributes[(x)])
//
// Define the title to be displayed for this module.
//
char *TitleString =
"UW/PC version 2.01, Copyright (C) 1990-1991 Rhys Weatherley\n"
"UW/PC comes with ABSOLUTELY NO WARRANTY; see the file COPYING for details.\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; see the file COPYING for details.\n\n"
"Press ALT-Z for help on special keys.\n\n";
unsigned cdecl _stklen=8192;
int DebugMode;
FILE *DebugFile;
int main (int argc,char *argv[])
{
char *mesg;
DebugMode = 0;
if (argc > 1 && !strcmp (argv[1],"-debug"))
{
// Open a debugging file to help me with user problems //
if ((DebugFile = fopen ("UWDEBUG.OUT","wb")) != NULL)
DebugMode = 1;
} /* if */
UWConfig.doconfig (argv[0]); // Configure the program as necessary.
if (!HardwareScreen.init (0))
{
fprintf (stderr,"Cannot initialise screen - not enough memory\n");
return (0);
}
HardwareScreen.scroll (0,0,SCRN_WIDTH - 1,SCRN_HEIGHT - 2,0,
ATTR(ATTR_NORMAL));
HardwareScreen.scroll (0,SCRN_HEIGHT - 1,SCRN_WIDTH - 1,SCRN_HEIGHT - 1,0,
(UWConfig.DisableStatusLine ? 0x07 : ATTR(ATTR_STATUS)));
HardwareScreen.cursor (0,4);
HardwareScreen.shape ((CursorShapes)UWConfig.CursorSize);
if (UWConfig.EnableMouse)
UWConfig.EnableMouse = InitMouse ();
InitKeyboard ();
InitTimers ();
mesg = UWMaster.start ();
TermTimers ();
TermKeyboard ();
if (UWConfig.EnableMouse)
TermMouse ();
HardwareScreen.term ();
if (mesg)
fprintf (stderr,"%s\n",mesg);
if (DebugMode)
fclose (DebugFile);
return (0);
} // main //
//
// Send a command-line for the DSZ program to do a ZMODEM file transfer.
//
static void SendZModemCommand (char *cmd,char *file)
{
static char cmdline[256];
sprintf (cmdline,"%s port %d portx %x,%d ha off %s %s",
UWConfig.ZModemCommand,
UWConfig.ComPort,
comports[UWConfig.ComPort - 1],
4 - ((UWConfig.ComPort - 1) % 2),cmd,file);
UWMaster.direct (1); // Turn on direct communications.
UWMaster.jumpdos (cmdline); // Do the ZMODEM command line.
UWMaster.direct (0); // Turn off direct communications.
} // SendZModemCommand //
//
// Define the query dialog boxes used by this module.
//
class QuitQueryBox : public UWQueryBox {
public:
QuitQueryBox (UWDisplay *wind) :
UWQueryBox (wind,"Exit UW/PC? Yes or No",21) {};
virtual void process (int index)
{ if (index < 2) UWMaster.terminate = 1; // Kill UW/PC.
terminate (); };
};
class ExitQueryBox : public UWQueryBox {
public:
ExitQueryBox (UWDisplay *wind) :
UWQueryBox (wind,"Exit? Yes or No",15) {};
virtual void process (int index)
{ if (index < 2) UWMaster.exitmulti = 1; // Exit protocol 1.
terminate (); };
};
class HangupQueryBox : public UWQueryBox {
public:
HangupQueryBox (UWDisplay *wind) :
UWQueryBox (wind,"Hangup? Yes or No",17) {};
virtual void process (int index)
{ if (index < 2) UWMaster.sendbreak (); // Send a BREAK.
terminate (); };
};
class BreakQueryBox : UWQueryBox {
public:
BreakQueryBox (UWDisplay *wind) :
UWQueryBox (wind,"Send BREAK? Yes or No",21) {};
virtual void process (int index)
{ if (index < 2) UWMaster.hangup (); // Hangup the modem.
terminate (); };
};
static char *asciimsgs[] =
{"Enter name of file to upload, ^X to clear line, or ESC to abort.",
"Enter name of file to download, ^X to clear line, or ESC to abort.",
"Enter name of capture file, ^X to clear line, or ESC to abort."};
class AsciiEditBox : public UWEditBox {
protected:
int kind;
public:
AsciiEditBox (UWDisplay *wind,int Kind) :
UWEditBox (wind,asciimsgs[Kind],MAX_EDIT_SIZE)
{ kind = Kind; };
virtual void process (int esc)
{ terminate ();
if (!esc && buffer[0] != '\0')
new UWAsciiFileTransfer (window,kind,buffer);
};
};
class FileEditBox : public UWEditBox {
protected:
int upload;
int kind;
public:
FileEditBox (UWDisplay *wind,int Upload,int Kind) :
UWEditBox (wind,asciimsgs[!Upload],MAX_EDIT_SIZE)
{ kind = Kind; upload = Upload; };
virtual void process (int esc)
{ terminate ();
if (!esc && buffer[0] != '\0')
new UWXYFileTransfer (window,kind,!upload,buffer);
};
};
class ZModemEditBox : public UWEditBox {
public:
ZModemEditBox (UWDisplay *wind) :
UWEditBox (wind,asciimsgs[0],MAX_EDIT_SIZE) {};
virtual void process (int esc)
{ terminate ();
if (!esc && buffer[0] != '\0')
{
SendZModemCommand ("sz -b",buffer);
send ('\r'); // Send ^M to get command line back.
}
};
};
class FileQueryBox : public UWQueryBox {
protected:
int upload;
public:
FileQueryBox (UWDisplay *wind,int Upload) :
UWQueryBox (wind,UWMaster.protocol == 0 ?
"[A]scii, [X]modem or [Z]modem?" :
"[A]scii, [X]modem",
UWMaster.protocol == 0 ? 30 : 20,
UWMaster.protocol == 0 ? "\033aAxXzZ" :
"\033aAxX")
{ upload = Upload; };
virtual void process (int index)
{ if (index < 1)
terminate ();
else if (index < 3)
{
terminate ();
new AsciiEditBox (window,(upload ? ASCII_UPLOAD
: ASCII_DOWNLOAD));
}
else if (index < 5)
{
terminate ();
new FileEditBox (window,upload,XMOD_ORIGINAL);
}
else if (index < 7)
{